/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-04-28
 * Time: 17:48
 */
public class test2 {

    static int a = 0;

    public static void main(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(() ->{
            while (true){
                synchronized (locker){
                    if(a>200){
                        break;
                    }
                    if(a%2==0){
                        System.out.println(Thread.currentThread().getName()+"-"+a);
                        a++;
                        locker.notify();
                    }else{
                        try {
                            locker.wait();
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }
            }
        });
        t1.setName("t1");


        Thread t2 = new Thread(() ->{
            while(true){
                synchronized (locker){
                    if(a>200){
                        break;
                    }
                    if(a%2==1){
                        System.out.println(Thread.currentThread().getName()+"-"+a);
                        a++;
                        locker.notify();
                    }else {
                        try {
                            locker.wait();
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }
            }
        });
        t2.setName("t2");
        t1.start();
        t2.start();
    }
}
